package com.sdhs.paas.nativedbdemo.service;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdhs.paas.nativedbdemo.bean.UcAppBean;
import com.sdhs.paas.nativedbdemo.repository.UcAppMapper;
import com.sdhs.paas.nativedbdemo.repository.UserMapper;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.sdhs.paas.sdk.base.page.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.nativedbdemo.repository")
@Service
public class UcAppService extends BaseDao<UcAppBean, UcAppMapper, Integer>{
	@Override
	public String getMapperNamespace() {
		return UcAppMapper.class.getName();
	}
	
	@Autowired
	private UcAppMapper ucAppMapper;
	
	@SuppressWarnings("deprecation")
	public Page<UcAppBean> getPageUcAppList(BasePage pageRequest, UcAppBean ucAppBean) {
		ucAppBean.setIsDelete(0);
		pageRequest.setFilters(ucAppBean);
		Page<UcAppBean> page = pageQuery(pageRequest);
		return page;
	}

	@Transactional(rollbackFor = Exception.class)
	public boolean saveUcApp(UcAppBean ucAppBean) {
		try {
			ucAppBean.setCtime(System.currentTimeMillis());
			ucAppBean.setUtime(System.currentTimeMillis());
			int count = ucAppMapper.insertUcApp(ucAppBean);
			return count == 1;
		} catch (Exception e) {
			throw new PaasBaseException(e, "500", "数据库插入异常！");
		}
	}

	@Transactional(rollbackFor = Exception.class)
	public boolean updateUcApp(UcAppBean ucAppBean) {
		try {
			ucAppBean.setUtime(System.currentTimeMillis());
			int count = ucAppMapper.updateUcApp(ucAppBean);
			return count == 1;
		} catch (Exception e) {
			throw new PaasBaseException(e, "500", "数据库插入异常！");
		}
	}

	public UcAppBean getUcAppDetail(String id) {
		return ucAppMapper.getUcAppDetail(id);
	}
}
